//index.js
const app = getApp()
const DB = wx.cloud.database();
let len = "";
let len2 = "";
Page({
    data: {
        type: wx.getStorageSync('user').xinwentype,
        // top标签显示（默认不显示）
        backTopValue: false,
        orderItem: [],
        orderItem2: [],
        banner: [{
                img: '../../images/aaa.jpg'
            },
            {
                img: '../../images/bbb.png'
            },
        ],
    },

    onLoad: function () {

    },

    onShow() {

        len2 = this.data.orderItem2.length

        DB.collection('news').where({
            zhanghao: wx.getStorageSync('user').zhanghao,
            mima: wx.getStorageSync('user').mima,

        }).skip(len).orderBy('time_order', 'desc').get().then(res => {

            console.log("b", res)
            wx.hideLoading();
            this.setData({
                orderItem2: res.data
            })
            console.log("this", this.data.orderItem2)
        })

    },

    shanchu(e) {
        let that = this;
        wx.showModal({
            title: '温馨提示',
            content: '是否删除？',
            confirmText: "是",
            cancelText: "否",
            success(res) {
                if (res.confirm) {
                    wx.showLoading({
                        title: '删除中',
                    })
                    wx.cloud.callFunction({
                        name: "update",
                        data: {
                            action: "shanchuxw",
                            id: e.currentTarget.dataset.id,
                        }
                    }).then(res => {
                        wx.hideLoading({
                            success: (res) => {},
                        })

                        DB.collection('news').where({
                            zhanghao: wx.getStorageSync('user').zhanghao,
                            mima: wx.getStorageSync('user').mima,

                        }).orderBy('time_order', 'desc').get().then(res => {

                            wx.hideLoading();
                            that.setData({
                                orderItem2: res.data
                            })
                        })

                    })
                } else if (res.cancel) {}
            }
        })
    },

    goDetail(e) {
        wx.navigateTo({
            url: '../newsdetail/index?id=' + e.currentTarget.dataset.id,
        })
    },





})